<?php
/**
* Resources output resources from given path
* This class is used to get, check url
*
* @author Patrice Ferlet <metal3d@copix.org> 
* @license http://opensource.org/licenses/lgpl-3.0.html GNU Lesser General Public License Version 3.0 (LGPLv3)
*/

$path = $_GET['path'];
$header = qmimetype($path);
header ('Content-type: '.$header);

$content = file_get_contents($path);
$dir = dirname($path);

if(strpos($header, 'css') !== false) {
    $content = preg_replace('/url\((.*?)\)/','url(resource.php?path='.$dir.'/\\1)',$content);
}
header ('Content-Length: '.strlen($content));
echo $content;
exit;



function qmimetype($file) {
 $ext=array_pop(explode('.',$file));
 foreach(file('/etc/mime.types') as $line)
   if(preg_match('/^([^#]\S+)\s+.*'.$ext.'.*$/',$line,$m))
       return $m[1];
  return 'application/octet-stream';
}
